package b3.scene.home
{
	import as3isolib.core.as3isolib_internal;
	import as3isolib.display.IsoSprite;
	import as3isolib.display.scene.*;
	import as3isolib.geom.IsoMath;
	import as3isolib.geom.Pt;
	import as3isolib.graphics.Stroke;
	
	import b3.config.*;
	
	import flash.display.*;
	import flash.geom.*;
	import flash.text.*;
	
	use namespace as3isolib_internal;
	
	public class CoordinateGrid extends IsoGrid
	{
		public function CoordinateGrid()
		{
			super();
			addCoordinates();
		}
		
		override protected function drawGeometry ():void
		{
			var g:Graphics = mainContainer.graphics;
			g.clear();
			
			
			var color:uint = 0xAAAAAA; 
			var stroke:Stroke = new Stroke(0, color, 0.5);
			stroke.apply(g);
			
			
			var m:int = int(gridSize[0]);
			var cSize:Number = cellSize - 8;
			for (var i:int = 0; i < 30; i++)
			for (var j:int = 0; j < 30; j++)
			{
				var tempPt:Pt = new Pt(i * cellSize, j * cellSize);
				var radiusW:uint = 160;
				var radiusH:uint = 90;
				var redColors:Array = [ color, color ];
				var alphas:Array = [ 1, 0 ];
				var ratios:Array = [ 100, 255 ];
				var xMatrix:Matrix = new Matrix();
	//			xMatrix.createGradientBox(radiusW * 2, radiusH * 2, 0, pt.x - radiusW, pt.y - radiusH);
	//			g.lineGradientStyle(GradientType.RADIAL, redColors, alphas, ratios, xMatrix);
				
	//			while (i <= m)
	//			{
	//				pt = IsoMath.isoToScreen(new Pt(cSize * i));
	//				g.moveTo(pt.x, pt.y);
	//				
	//				pt = IsoMath.isoToScreen(new Pt(cSize * i, cSize * gridSize[1]));
	//				g.lineTo(pt.x, pt.y);
	//				
	//				i++;
	//			}
	//			
	//			i = 0;
	//			m = int(gridSize[1]);
	//			while (i <= m)
	//			{
	//				pt = IsoMath.isoToScreen(new Pt(0, cSize * i));
	//				g.moveTo(pt.x, pt.y);
	//				
	//				pt = IsoMath.isoToScreen(new Pt(cSize * gridSize[0], cSize * i));
	//				g.lineTo(pt.x, pt.y);
	//				
	//				i++;
	//			}
				
				//画高亮部分
				stroke = new Stroke(3, color);
				stroke.apply(g);
				var pt:Pt = new Pt();
				pt = IsoMath.isoToScreen(new Pt(tempPt.x, tempPt.y));
				g.moveTo(pt.x, pt.y);
	
				pt = IsoMath.isoToScreen(new Pt(tempPt.x + cSize, tempPt.y));
				g.lineTo(pt.x, pt.y);
				
				pt = IsoMath.isoToScreen(new Pt(tempPt.x + cSize, tempPt.y + cSize));
				g.lineTo(pt.x, pt.y);
				
				pt = IsoMath.isoToScreen(new Pt(tempPt.x, tempPt.y + cSize));
				g.lineTo(pt.x, pt.y);
				
				pt = IsoMath.isoToScreen(new Pt(tempPt.x, tempPt.y));
				g.lineTo(pt.x, pt.y);
				
				
	//			pt = IsoMath.isoToScreen(new Pt(cSize * highlight[2], cSize * highlight[1]));
	//			g.lineTo(pt.x, pt.y);
	//			
	//			pt = IsoMath.isoToScreen(new Pt(cSize * highlight[2], cSize * highlight[3]));
	//			g.lineTo(pt.x, pt.y);
	//			
	//			pt = IsoMath.isoToScreen(new Pt(cSize * highlight[0], cSize * highlight[3]));
	//			g.lineTo(pt.x, pt.y);
	//			
	//			pt = IsoMath.isoToScreen(new Pt(cSize * highlight[0], cSize * highlight[1]));
	//			g.lineTo(pt.x, pt.y);
	
				
			}
			
			g.endFill();
		}
		
		private function createCoordinateSprite(pt:Point):Sprite
		{
			var coordinateSprite:Sprite = new Sprite();
			var titleText:TextField = new TextField();
			titleText.selectable = false;
        	titleText.autoSize = TextFieldAutoSize.LEFT;
			titleText.defaultTextFormat = new TextFormat("微软雅黑", 13, 0x000000);
			titleText.text = "----(" + pt.x + "," + pt.y + ")";
			coordinateSprite.addChild(titleText);
			return coordinateSprite;
		}
		
		private function addCoordinates():void
		{
			for (var i:int = 0; i < Config.townConfigs[0].sectionConfigs.length; i++)
			{
				var sectionConfig:SectionConfig = Config.townConfigs[0].sectionConfigs[i];
				var globalPointX:int = sectionConfig.globalPoint[0];
				var globalPointY:int = sectionConfig.globalPoint[1];
				var pts:Array = sectionConfig.sectionPoints;
				for (var j:int = 0; j < pts.length; j++)
				{
					var pt:Point = pts[j];
					var dark:IsoSprite = new IsoSprite();
					var gridWidth:int = Town.gridWidth;
					dark.setSize(gridWidth, gridWidth, gridWidth);
					dark.sprites = [createCoordinateSprite(pt)];
					dark.moveTo(pt.x * gridWidth, pt.y * gridWidth, 0.2);
					addChild(dark);
				}
			}
		}
	}
}